package com.cee.sch.job.service;

import com.cee.sch.job.dto.ScheduleJobDTO;
import com.cee.sch.job.model.ScheduleJob;
import com.github.pagehelper.PageInfo;
import org.quartz.SchedulerException;

import java.text.ParseException;

public interface ScheduleJobService {

    /**
     * Enquire data from VIS_SYS_SCH_JOB join QRTZ_JOB_DETAILS & QRTZ_CRON_TRIGGERS by criteria
     * @param query
     * @return
     */
    public PageInfo<ScheduleJobDTO> getScheduleJobPageInfo(ScheduleJobDTO query);

    /**
     * Add a new job, if jobType is 'HTTP', use httpJobData, else if jobType is 'LOCAL', use jobDataMap
     * @param scheduleJob
     * @return
     */
    public ScheduleJobDTO addScheduleJob(ScheduleJobDTO scheduleJob) throws SchedulerException, ParseException;

    /**
     * Update a job, user may update jobName, jobGroupName, description, cronExpression, the logic is that
     * 1.check the schedule job whether running (QRTZ_TRIGGERS.TRIGGER_STATE), if not then update, otherwise not allow and alert
     * 2.delete the old quartz job and add a new quartz job so that refers to original schedule job
     * QRTZ_TRIGGERS.TRIGGER_STATE:
     * WAITING:等待
     * PAUSED:暂停
     * ACQUIRED:正常执行
     * BLOCKED：阻塞
     * ERROR：错误
     * @param scheduleJob
     * @return
     */
    public ScheduleJobDTO updateScheduleJob(ScheduleJobDTO scheduleJob) throws SchedulerException, ParseException;

    /**
     * Delete a job logically
     * 1.check the schedule job whether running, if not then update as 'D', otherwise not allow and alert
     * @param visSysSchJobKey
     * @return
     */
    public void deleteScheduleJob(Long visSysSchJobKey) throws SchedulerException;

    /**
     * Enquire a job by jobName and jobGroupName
     * @param jobName
     * @param jobGroupName
     * @return
     */
    public ScheduleJobDTO getScheduleJobByNameAndGroup(String jobName, String jobGroupName) throws SchedulerException;


    public ScheduleJob getScheduleJobDetailById(Long id) throws SchedulerException;

    public ScheduleJob getScheduleJobById(Long id);

    /**
     * update scheduleJob enableInd = N ,  暂停一个job
     * @param visSysSchJobKey
     */
    public void disableScheduleJob(long visSysSchJobKey) throws SchedulerException;

    /**
     * update scheduleJob enableInd = Y , 恢复一个job
     *
     * @param visSysSchJobKey
     */
    public void enableScheduleJob(long visSysSchJobKey) throws SchedulerException;

    public void resetScheduleJob();
}
